<%@page import="com.crm.util.Constants"%>
<%@page import="com.crm.util.CrmUtil"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/page/public/taglib.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>核对查询</title>
<%@ include file="/WEB-INF/page/public/contentmeta.jsp"%>
<link rel="stylesheet" href="<%=basePath%>css/global.css" media="all" />
<link rel="stylesheet" href="<%=basePath%>plugins/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="<%=basePath%>css/system.css" media="all">
<link rel="stylesheet" href="<%=basePath%>css/tab.css" media="all" />

<style type="text/css">
	.layui-form-label i { color:red; padding-right: 3px; }
</style>
 
</head>
<body>
<div class="admin-tab TM-tab admin-checkQuery">

   <form class="layui-form TM-entering-form" action="/customer/checkcustomer${customertype}" id="checkform"  method="post">
        <div class="layui-form-item">
            <label class="layui-form-label"><i>*</i>唯一标识符 : </label>
            <div class="layui-input-inline" style="width:200px;">
                <input type="text" name="keyWord" id="keyWord" value="${param.keyWord}" autocomplete="off" class="layui-input">
                <input name="skipToPage" id="skipToPage"  type="hidden" value="${pager.pageNo}"   > 
                <input type="hidden" value="${customertype}" id="type" name="type">
            </div>
        </div>
        <!-- <div class="layui-form-item">
            <label class="layui-form-label">所有人 : </label>
            <div class="layui-input-inline">
                <input type="text" name="title" lay-verify="title" autocomplete="off" class="layui-input">
            </div>
        </div> -->
        <%-- <div class="layui-form-item address">
            <label class="layui-form-label">所在省份 : </label>
            <div class="layui-input-inline" style="width:100px;">
                <select name="province" id="province"  lay-filter="province" class="provinceclass" <c:if test="${cuinfo.id>0}">  disabled="disabled"</c:if> >
                        <option value="" selected>全部</option>
                        <c:forEach var="prov" items="${province}" varStatus="p1">
                        	<option value="${prov.id}"  
                        	<c:if test="${param.province==prov.id}">selected</c:if>
                        	>${prov.provincename}</option>
                        </c:forEach>
                  </select>
            </div>
            <div class="layui-input-inline" style="width:100px;">
                  <select name="city" id="city"  lay-filter="city" value="${param.city}"<c:if test="${cuinfo.id>0}">  disabled="disabled"</c:if>>
                    	<option value="">请选择市</option>
                    </select>
            </div>
            
        </div> --%>
        <div class="layui-form-item " >
            <div class="layui-input-inline layui-form-btn" style="width:350px;" >
                <button class="layui-btn cx"   >查询</button>
                <input type="button" class="layui-btn  cleanform" value="清空">
                 <input type="button" class="layui-btn  luru" value="录入">
                 <a class="layui-btn refreshbtn" href="javascript:;">刷新</a>
            </div>
        </div>
    </form>
    <div class="entering">
        <h4>资源列表</h4>
        <table class="site-table table-hover TM-table3">
            <thead>
            <tr>
                <th style="width:5%;">序号</th>
                <th style="width:${customertype==0?"10":"30"}%;">${customertype==0?"姓名":"企业名称"}   </th>
                <c:if test="${customertype==0}">
                <th style="width:20%;">证书及专业</th>
                </c:if>
                <!-- <th style="width:105px;">地址</th> -->
                <th style="width:15%;">所在地区</th>
               <!--  <th style="width:125px;">证书</th> -->
                <th style="width:10%;">成熟等级</th>
                <th style="width:10%;">所有人</th>
                <th style="width:10%;">最后跟进时间</th>
                <th style="width:20%;">操作</th>
            </tr>
            </thead>
            <tbody>
            <c:forEach  items="${pager.resultList}"  var="ckobj"  varStatus="idx">
            	  <tr id="list${ckobj.id}" cname="${ckobj.cname}">
		                <td>${idx.count}</td>
		                <td>${ckobj.cname}</td>
		                 <c:if test="${customertype==0}">
		                	<td>${ckobj.technicalpost}</td>
		                </c:if>
		                <!-- <td></td> -->
		                <td>${ckobj.address}</td>
		                <td   ><dic:cf value="${ckobj.state}" name="customer_state" type="1"/> </td>
		                <td>${ckobj.createusersname}</td>
		                <td class="seenote seenote${ckobj.id}" data="${ckobj.id}"  dstate="${ckobj.state}"  dck="${ckobj.uid==sessionScope.user.id?true:false}">${ckobj.updatedate.substring(0,10)}</td>
		                <td>
		                   <c:if test="${ckobj.state==4}">
		                   	<a target="_blank" href="/customer/updatecustomer${ckobj.id}" class="layui-btn layui-btn-normal layui-btn-mini" data="${ckobj.id}">查看</a>
		                   	<a  href="javascript:;"  class="layui-btn layui-btn-normal layui-btn-mini hqbtn"  data="${ckobj.id}">获取</a>
		                   </c:if> 
		                  <c:if test="${ckobj.state!=4}">
		                  	<c:if test="${ckobj.uid==sessionScope.user.id}">
		                  		<a target="_blank" href="/customer/updatecustomer${ckobj.id}" class="layui-btn layui-btn-normal layui-btn-mini" data="${ckobj.id}">查看</a> 
		                  	</c:if>
		                  	<!-- 索要的显示判断 -->
		                  	<!-- 现在的索要 -->
		                  	<c:if test="${ckobj.uid!=sessionScope.user.id}">
		                  		
		                  		<c:set var="nowdate" value="${nowdate}" scope="request"/><!-- 当前时间 -->
			                  	<c:set var="enddate" value="${ckobj.contractItem.endtime.substring(0,10)}" scope="request"/><!-- 合同结束时间 -->
			                  	
			                  	<%
			                  				                  		String nowdate = (String)request.getAttribute("nowdate");//当前日期
			                  				                  		                  				                  		                  				                  		                  		String endtime = (String)request.getAttribute("enddate");//合同结束日期
			                  				                  		                  				                  		                  				                  		                  		if ((endtime == null || endtime.length() < 1) || !CrmUtil.checkIsPastDue(endtime, nowdate)){
			                  				                  	%>
			                  			<a  href="javascript:;"  class="layui-btn layui-btn-normal layui-btn-mini askFor" data="${ckobj.id}" >索要</a> 
			                  	<%
 			                  		} else  {
 			                  	 			                  	 			                  		                  			if (CrmUtil.checkTimeDifference(endtime, nowdate, Constants.TIMEDIFFERENCE))
 			                  	%>
		                  				<a  href="javascript:;"  class="layui-btn layui-btn-normal layui-btn-mini askFor" data="${ckobj.id}" >索要</a> 
		                  		<%
			                  		}
			                  	%>
		                  	</c:if>
		                  	<!-- 这里注释的是原先带有联系时间判断的索要判断 -->
		                  	<%-- <c:if test="${ckobj.uid!=sessionScope.user.id}">
		                  	
			                  	<c:set var="nowdate" value="${nowdate}" scope="request"/>
			                  	<c:set var="enddate" value="${ckobj.contractItem.endtime.substring(0,10)}" scope="request"/>
			                  	<c:set var="updatedate" value="${ckobj.updatedate.substring(0,10)}" scope="request"/>
			                  	
			                  	<%
			                  	String nowdate = (String)request.getAttribute("nowdate");//当前日期
			                  	String endtime = (String)request.getAttribute("enddate");//合同结束日期
			                  	String updatetime = (String)request.getAttribute("updatedate");//最后联系时间
			                  	
			                  	if ((endtime == null || endtime.length() < 1) || !JycrmUtil.checkIsPastDue(endtime, nowdate)) {//到期时间为空或到期时间在当前时间之前(也就是已到期)
			                  		//看跟进时间与当前时间的差值有没有超过30天,如果超过30天,显示索要.
			                  		if (!JycrmUtil.checkTimeDifference(nowdate, updatetime, Constants.TIMEDIFFERENCE)) {
			                  	%>
			                  			<a  href="javascript:;"  class="layui-btn layui-btn-normal layui-btn-mini askFor" data="${ckobj.id}" >索要</a> 
			                  	<%
			                  		} 
			                  	} else {//到期时间不为空且到期时间在当前时间之后(没到期)
			                  		//这里的条件:到期时间与当前时间的差值小于30天并且跟进记录与到期时间的差值大于30天,显示索要
			                  		if (JycrmUtil.checkTimeDifference(endtime, nowdate, Constants.TIMEDIFFERENCE)&&!JycrmUtil.checkTimeDifference(endtime, updatetime, Constants.TIMEDIFFERENCE)){
			                  			%>
			                  				<a  href="javascript:;"  class="layui-btn layui-btn-normal layui-btn-mini askFor" data="${ckobj.id}" >索要</a> 
			                  			<%
			                  		}
			                  		
			                  	}
			                  	%>
		                  	</c:if> --%>
		                  </c:if>  
		                </td>
		            </tr>
            </c:forEach>
            
            </tbody>
        </table>
        <div class="admin-table-page">
            <div id="page" class="page"></div>
        </div>
    </div>
</div>
<!--索要弹窗 -->
<div id="TM-layui-askFor" style="display:none;">
    <div class="TM-ask-for" style="padding:10px 20px;">
        <h4 style="margin-bottom:10px;">备注</h4>
        <textarea name="" id="askforremark" cols="60" rows="5"></textarea>
    </div>
</div>
<div class="Mask ZZmask"></div>

<script type="text/javascript" src="<%=basePath%>js/qualify/zizhisel.js"></script>
<script type="text/javascript" src="<%=basePath%>js/jobsel/job.js"></script>

<script>
    layui.use(['laypage','form','laydate'], function() {
        var $ = layui.jquery,
                layer = layui.layer,
                laypage = layui.laypage;
                var form = layui.form();
        
              
           $(".co-address").on("click",function(){
            		var id = $(this).attr("data");
            		parent.infoShow(id);
            	 
            });         
                
        //省份城市选择
    	/* form.on('select(province)', function(data){
    		var id = $("#province").val();
    		var html = city.getCityByPid(id);
			$("#city").html(html);
			//更新渲染  
	    	form.render('select'); 
    	}); */
        
    	   $("#zizhiType").jobsel({
           	'inputName' : "category"
           }).init();

    	   var id = $("#province").val();
    	   if(id>0){
    		   var html = city.getCityByPid(id);
   			   $("#city").html(html);
   			   var cv =  $("#city").attr("value"); 
   			   if(cv>0){
   				 $("#city").val(cv); 
   			   }
   			   //更新渲染  
   	    	   form.render('select'); 
    		   
    	   }
   		   //点击查询 设置页面为第一页
    	   $('.cx').on('click',function(){
    		   $("#skipToPage").val(1);
    	   });
    	   //清空表单
    	   $('.cleanform').on('click',function(){
    		    $("#keyWord").val("");
    		    $("#province").val("");
    		    $("#city").html("<option value=\"\">请选择市</option>");
    		    $("#city").val("");
    		    $("#category").val("");
    		    $("#zizhiType").val("");
    		    $("#state").val("0");
    		    form.render(); 
    	   });  
    	 
    	   $(".luru").on("click",function(){
    		   var type = $("#type").val();
       		   parent.layer.open({
     			  type: 2, 
     			  title:"录入信息",
     			  area: ['95%', '95%'],
     			  content: "/customer/addcustomer"+type, //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
     		 }); 
    	   })
         
    	   
    	 
        //索要弹窗
        $('.askFor').on('click',function(){
        	var id =$(this).attr("data"),remark =$("#askforremark").val();
            layer.open({
                type:1,
                content:$('#TM-layui-askFor').html(),
                btn:['确定','取消'],
                btnAlign:'c',
                shade: [.6,'#000'],
                shadeClose:true,
                title:'索要',
                area:'auto',
                maxWidth:800,
                yes: function(layero, index){
                	$.ajax({
        				type : "post",
        				url : "/customer/claimsave",
        				data : {cusid:id,remark:remark},
        				dataType : "json",
        				success : function(data){
        					if(data=="1"){
        						 layer.close(layero);
        						 layer.msg("索要成功",{icon: 1},function(){
            						//window.location.reload();
            					});
        					}else{
        						layer.msg("索要失败",{icon: 2} );
        					} 
        				}
        			});
                	
                }
            });
        });

        //分页
         laypage({
            cont: 'page',
            curr:'${pager.pageNo}'
            ,pages: '${pager.totalPages}' //总页数
            ,
            groups: 5 //连续显示分页数
            ,
            skip: true,
            jump: function(obj, first) {
                //得到了当前页，用于向服务端请求对应数据
                var curr = obj.curr;
                if(!first) {
                	$("#skipToPage").val(curr);
                	$("#checkform").submit();
                }
            }
        });  
    
        
        //更新渲染
        form.render('select');
        
        
      //获取按钮(单条)
      $(".hqbtn").on("click",function(){
    		var id = $(this).attr("data");
    		var type = $("#type").val();
    		//跳转地址 以后要是有其他参数了再加
    		var url = "/customer/entman/ty1_st4";
    		var cname = $(this).parent().parent().attr("cname");
    		//获取跟升级一样的 就是把公共库的升级进线索库
    		$.ajax({
    			type : "post",
    			url : "/customer/updatecustomerstate",
    			data : {value : id , state : 4,type : type,cname:cname},
    			dataType : "json",
    			success : function(data){
    				$("#list"+id).hide();
    				layer.msg('资源获取成功', {icon: 1});
    			}
    		});
    	});  
        
      //验证
		$("#checkform").validate({
			
	    	rules: {
	    		keyWord : {
	    			required:true,
	    		},
	    		city: {
	    			required:true,
	    		},
	    		province: {
	    			required:true,
	    		} 
	    	},
	    	messages: {
	    		keyWord : {
	    			required:"请输入关键字",
	    		},
	    		city: {
	    			required:"请选择城市",
	    		},
	    		province: {
	    			required:"请选择省份",
	    		} 
	    	},
	    	errorPlacement: function(error, element) {
				layer.tips(error.text(), element, {
					tips: [2,tipColor],
	     		 tipsMore: true
	     		});
	   		}, 
	   	 submitHandler: function(form) {
	   		  var ky = $.trim($("#keyWord").val());
	   	      $("#keyWord").val(ky);
	   		  form.submit(); 
	      }
	    });
      
		$(document).on("mouseover",".seenote",function(){
    		layer.closeAll();
    		var data = $(this).attr("data"),dstate = $(this).attr("dstate"),dck = $(this).attr("dck");
    		//layer.msg("测试一下"+data);
    		var ele = $(".seenote"+data);
    		
    		if(dstate==4){
    			gjjl(ele,data);
    		}else{
    		
    			if(dck=="true"){
    				gjjl(ele,data);
    			}else{
    				layer.tips("无权查看该信息跟进记录", ele, {
    					tips: [1,'#f7625e'],
    					area:["400px"],
    					time:5000,
    					
    	     		 tipsMore: true
    	     		});
    			}
    			
    			
    		}
    		
    	
    	});
		
		
		function gjjl(ele,data){
			$.ajax({
    			type : "post",
    			url : "/customer/customercontactsbycusid",
    			data : {id : data},
    			dataType : "json",
    			async: false,
    			contentType: "application/x-www-form-urlencoded; charset=utf-8",
    			success : function(data){
    				
    				var jsondata = eval(data);
    				var html = "";
    				if (jsondata.length > 0) {
    					$.each(data, function (i, item) {
        		        	html += "["+ item.updatedate.substring(0,10) +"]"+item.remark+"------"+item.uname+"<br/>";
        		        });
    				} else {
    					html = "该数据暂无联系记录";
    				}
    		        
    				
    				layer.tips(html, ele, {
    					tips: [1,'#f7625e'],
    					area:["400px"],
    					time:5000,
    					
    	     		 tipsMore: true
    	     		});
    			}
    		})
			
		}
        
    });
</script>
</body>
</html>